﻿using Jint;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using T.FAS.Runtime.Base.Entity;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using T.FAS.Runtime.Expression.Entity;
using T.FAS.Runtime.Expression.Service;
using System.Dynamic;
using T.FAS.Runtime.Expression.Plugin;

namespace T.FAS.Runtime.Expression.UnitTest
{
    [TestClass]
    public class AssertUnit
    {
        /// <summary>
        /// IsTrue
        /// </summary>
        [TestMethod]
        public void ExecuteIsTrue()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Assert.IsTrue(1==1)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("Assert.IsTrue(1==2)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// IsFalse
        /// </summary>
        [TestMethod]
        public void ExecuteIsFalse()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Assert.IsFalse(1==3)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("Assert.IsFalse(1==1)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// IsNotNull
        /// </summary>
        [TestMethod]
        public void ExecuteIsNotNull()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Assert.IsNotNull(1)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("var a;  Assert.IsNotNull(a)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// IsNull
        /// </summary>
        [TestMethod]
        public void ExecuteIsNull()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("var a;  Assert.IsNull(a)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("Assert.IsNull(1)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// AreEqual
        /// </summary>
        [TestMethod]
        public void ExecuteAreEqual()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Assert.AreEqual(2,2);", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("Assert.AreEqual(2,3);", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
        /// <summary>
        /// AreNotEqual
        /// </summary>
        [TestMethod]
        public void ExecuteAreNotEqual()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            ExprResult exprResult = ExprService.GetInstance.JSExecute("Assert.AreNotEqual(1,3)", dic);
            Assert.IsTrue(exprResult.State == ResultState.Success);

            exprResult = ExprService.GetInstance.JSExecute("Assert.AreNotEqual(2,2);", dic);
            Assert.IsTrue(exprResult.State == ResultState.Fail);
        }
    }
}
